package com.hakim.wfb.customer.service.impl;

import com.hakim.wfb.admin.params.interest.GetConsumeInterestParam;
import com.hakim.wfb.bean.ConsumeInterest;
import com.hakim.wfb.customer.params.consume.*;
import com.hakim.wfb.customer.result.consume.ConsumeInterestView;
import com.hakim.wfb.customer.service.ConsumeInterestService;
import com.hakim.wfb.customer.service.convert.ConsumeInterestDtv;
import com.hakim.wfb.dao.ConsumeInterestDao;
import com.hkfs.fundamental.api.data.ObjectResultEx;
import com.hakim.wfb.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * Created by lenovo on 2017/7/18.
 */
@Service("consumeInterestService")
public class ConsumeInterestServiceImpl implements ConsumeInterestService {

    @Autowired
    private ConsumeInterestDao consumeInterestDao;

    /**
     * @param param
     * @return
     */
    @Override
    public ObjectResultEx<ConsumeInterestView> getInterest(com.hakim.wfb.customer.params.consume.GetConsumeInterestParam param) {
        ObjectResultEx<ConsumeInterestView> resultEx = new ObjectResultEx<>();
        return resultEx;
    }

    /**
     * @param param
     * @return
     */
    @Override
    public ObjectResultEx<ConsumeInterestView> getTodayInterest(GetTodayConsumeInterestParam param) {
        ObjectResultEx<ConsumeInterestView> resultEx = new ObjectResultEx<>();
        GetConsumeInterestParam getConsumeInterestParam = new GetConsumeInterestParam();
        getConsumeInterestParam.setRuleId(param.getRuleId());
        getConsumeInterestParam.setInterestDateTime(DateUtils.getNowDateShort());
        ConsumeInterest interestOfBeforeDay = consumeInterestDao.getConsumeInterest(getConsumeInterestParam);
        if (interestOfBeforeDay != null) {

            ConsumeInterestView view = ConsumeInterestDtv.convert(interestOfBeforeDay);

            resultEx.setDataObject(view);
            return resultEx.makeSuccessResult();
        }
        return resultEx.makeFailedResult("没有设置日息");
    }

//    @Override
//    public ListResultEx<ConsumeInterestView> list(ConsumeInterestParam param) {
//        ListResultEx<ConsumeInterestView> relist = new ListResultEx<ConsumeInterestView>();
//        try {
//            relist.setDataList(consumeIntrestDao.list(param));
//        } catch (Exception e) {
//            return relist.makeFailedResult("操作失败");
//        }
//        return relist;
//    }

//    @Override
//    public ResultEx add(ConsumeInterestParam param) {
//        ResultEx re = new ResultEx();
//        try {
//            ConsumeIntrest ci = new ConsumeIntrest();
//            ci.setCiRuleId(param.getCiRuleId());
//            ci.setCiDate(param.getCiDate());
//            ConsumeIntrest slist = consumeIntrestDao.getConsumeInterest(ci);
//            if (null != slist) {
//                // 存在则更新
//                slist.setCiIntrest(param.getCiIntrest());
//                consumeIntrestDao.update(slist);
//            } else {
//                // 不存在则加入
//                ci.setCiIntrest(param.getCiIntrest());
//                ci.setTid(UUIDGenerator.getUUID());
//                consumeIntrestDao.add(ci);
//            }
//            return re.makeSuccessResult();
//        } catch (Exception e) {
//            return re.makeFailedResult("操作失败");
//        }
//    }

//    @Override
//    public ObjectResultEx<ConsumeInterestView> getTodayIntrest(String ruleId) {
//        ObjectResultEx<ConsumeInterestView> resultEx = new ObjectResultEx<ConsumeInterestView>();
//        ConsumeIntrest t = new ConsumeIntrest();
//        t.setCiRuleId(ruleId);
//        t.setCiDate(DateUtils.getNowDateShort());
//        ConsumeIntrest intrestOfBeforeDay = consumeIntrestDao.getConsumeInterest(t);
//        if (intrestOfBeforeDay != null) {
//            ConsumeInterestView view = ConsumeIntrestDtv.convert(intrestOfBeforeDay);
//            resultEx.setDataObject(view);
//            return resultEx.makeSuccessResult();
//        }
//        return resultEx.makeFailedResult("没有设置日息");
//    }
}
